<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

class discussion extends CommonController
{
    public function discussion()
    {

        $res = Db::table('discussion')->order('page_id desc')->select();
        $this->assign('list', $res);
        return $this->fetch('discussion');
    }

    public function discussionPage()
    {
        return $this->fetch('publicPage');
    }

    public function showDisc($dis){
        $res=Db::table('discussion')->alias('d')-> join('user u','d.user_id=u.user_id')->where('d.page_id',$dis)->select();
		$comment=Db::table('comment_d')->alias('c')->join('user u','c.user_id=u.user_id')->where('c.page_id',$dis)->select();
		$this->assign('comment',$comment);		
		// var_dump($res);
		$this ->assign('list',$res);
		return $this->fetch('showDis');
    }

    public function submit($content,$title,$id)
    {
        $id=getId($id);
        $res = Db::table('discussion')->insert(
            [
                "page_time" => date("Y-m-d H:i:s"),
                "user_id" => $id,
                "page_title" => $title,
                "page_content" => $content,
            ]
        );
        return $res;
    }

    public function addcomment($comment,$id,$page_id){
		$res = Db::table('comment_d')->insert(["comment_content"=>$comment,"user_id"=>getId($id),"page_id"=>$page_id,"comment_time"=>date("Y-m-d h:i:s")]);
		return $res;
	}
}
